//
//  RadioTitleView.m
//  PetTown
//
//  Created by lanou3g on 15/5/31.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RadioTitleView.h"
#import "JSONKit.h"
#import "UIImageView+WebCache.h"
#import <QuartzCore/QuartzCore.h>
#define LHeight self.frame.size.height
#define LWidth  self.frame.size.width
@implementation RadioTitleView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {

        [self setSubViews];

    }
    return self;
}

//set方法
-(void)setDataDiction:(NSMutableDictionary *)dataDiction{
    _dataDiction = dataDiction;
    [self setSHowContent];
    
}
//添加视图
- (void)setSubViews{
    //顶部视图
    self.coverimgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LWidth, LHeight/2+ 10)];
    //头像
    self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_coverimgView.frame)+15, 26, 26)];
    _iconImgView.layer.masksToBounds = YES;
    _iconImgView.layer.cornerRadius = 13.0;

    //用户名
    self.unameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_iconImgView.frame)+5, CGRectGetMinY(_iconImgView.frame)+3, 100, 20)];
    _unameLabel.alpha = 0.7;
    _unameLabel.font = [UIFont systemFontOfSize:12];
    //收听人数
    self.musicvisitnumLabel = [[UILabel alloc] initWithFrame:CGRectMake(LWidth - 100, CGRectGetMinY(_unameLabel.frame), 90, 20)];
    //概述
    self.descLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_iconImgView.frame), LWidth-30, LHeight/2 - 50)];
    
    _musicvisitnumLabel.textColor = [UIColor lightGrayColor];
    _musicvisitnumLabel.font = [UIFont systemFontOfSize:14];
    
    _descLabel.numberOfLines = 0;
    _descLabel.textColor = [UIColor lightGrayColor];
    _descLabel.font = [UIFont systemFontOfSize:14];
    _descLabel.textAlignment = NSTextAlignmentLeft;


    
    [self addSubview:_coverimgView];
    [self addSubview:_iconImgView];
    [self addSubview:_unameLabel];
    [self addSubview:_musicvisitnumLabel];
    [self addSubview:_descLabel];
}


//添加内容
- (void)setSHowContent{
    NSURL * coverURL = [NSURL URLWithString:[_dataDiction objectForKey:@"coverimg"]];
    NSDictionary * dic = [_dataDiction objectForKey:@"userinfo"];
    NSURL * iconURL = [NSURL URLWithString:[dic objectForKey:@"icon"]];
    [_coverimgView sd_setImageWithURL:coverURL placeholderImage:[UIImage imageNamed:@"place.jpg"]];
    [_iconImgView sd_setImageWithURL:iconURL placeholderImage:[UIImage imageNamed:@"place.jpg"]];
    _descLabel.text = [_dataDiction objectForKey:@"desc"];
    _musicvisitnumLabel.text =[NSString stringWithFormat:@"♡ %@",[_dataDiction objectForKey:@"musicvisitnum"]];
    _unameLabel.text = [dic objectForKey:@"uname"];
    self.title = [_dataDiction objectForKey:@"title"];

}


@end
